<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Chord extends MY_Controller{

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/home
	 *	- or -  
	 * 		http://example.com/index.php/home/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
    function __construct()
    {
        parent::__construct();
		
		//Google Analytics ID
		$this->data['ga_id'] = 20;		
		
		//Load model
		$this->load->model('chord_model');
				
		//Load Chords Script
		$this->data['js'][] = "chordScript.js";
		$this->data['css'][] = "chordStyle.css";
		
		 //Load Library
  		$this->load->library('pagination');
		
		//Set SEO Tag
		$this->data['seo_title'] = 'คอร์ดเพลง เนื้อเพลง คอร์ดกีตาร์ แทปกีตาร์ | You2Play.com';
		$this->data['seo_keyword'] = 'คอร์ดเพลง, เนื้อเพลง, คอร์ดกีตาร์, แทปกีตาร์';				
    }
	
	/*Top Menu*/
	private function top_sub_menu()
	{
		//Filter Type
		$this->data['type'] = $this->uri->segment(1);
		if(!in_array($this->data['type'],array('new_released','recommend','hit'))) $this->data['type'] = "new_released";
		//Filter Media Type
		switch($this->uri->segment(2)):
			case 'thai':
				$this->data['media_type'] = 'thai';
				$this->data['media_type_text'] = 'เพลงไทย';
			break;
			case 'inter':
				$this->data['media_type'] = 'inter';
				$this->data['media_type_text'] = 'เพลงสากล';
			break;
			case 'asian':
				$this->data['media_type'] = 'asian';
				$this->data['media_type_text'] = 'เพลงเอเชียน';
			break;
			default:
				$this->data['media_type'] = 'all';
				$this->data['media_type_text'] = 'เพลงทั้งหมด';
		endswitch;
		//Filter Genre
		$this->data['genre'] = $this->uri->segment(3);
		$is_exist = $this->db->from('genre')->where(array('genre_alias' => ''.$this->data['genre'].''))->count_all_results();
		if(!empty($is_exist)):
			$dataGenre = $this->db->select('genre_name')->get_where('genre',array('genre_alias' => $this->data['genre']))->row();
			$this->data['genre_text'] = $dataGenre->genre_name;				
		else:
			$this->data['genre'] = "all";	
			$this->data['genre_text'] = "แนวเพลงทั้งหมด";			
		endif;
		
		$this->data['dataGenre'] = $this->db
		->order_by('genre_name ASC')
		->get('genre')
		->result();		
			
		return $this->load->view($this->router->class."/top_sub_menu",$this->data, TRUE);
	}
		
	/*Home*/	 
	public function index($category=NULL)
	{
		//Load Module
		$this->data['module'] = $this->module('chords');
		
		//Load Top Sub Menu
		$this->data['top_sub_menu'] = $this->top_sub_menu();				
		
		//Chords Thai
		if ( !$this->data['dataChordsThai'] = $this->memcache->get('dataChordsThai')):
			$this->data['dataChordsThai'] = $this->db->select('t.chords_id,t.song_id,t.views,t.chords_publish_date,j.song_name,j.artist_name,j.album_file_name,j.album_file_ext')
			->join('chords_info as j','j.chords_id=t.chords_id','INNER')
			->order_by('t.chords_publish_date DESC,t.chords_id DESC')
			->get_where('chords as t',"t.media_type_id = 1 AND t.is_publish = '1' AND t.chords_publish_date <= NOW()",16)
			->result();
			foreach($this->data['dataChordsThai'] as $value):
				if(!empty($value->song_id)):
					$dataAlbum = $this->db->select('j.album_file_name,j.album_file_ext')
					->join('album_info as j','j.album_id=t.album_id','INNER')
					->get_where('song_album as t',array('t.song_id' => $value->song_id,'is_default' => '1'),1)
					->row();
					$value->album_file_name = $dataAlbum->album_file_name;
					$value->album_file_ext = $dataAlbum->album_file_ext;
				endif;
			endforeach;			
			//Cache Set
			$this->memcache->set('dataChordsThai', $this->data['dataChordsThai'], $this->memcache_time);
		endif;
		
		//Chords Inter
		if ( !$this->data['dataChordsInter'] = $this->memcache->get('dataChordsInter')):
			$this->data['dataChordsInter'] = $this->db->select('t.chords_id,t.song_id,t.views,t.chords_publish_date,j.song_name,j.artist_name,j.album_file_name,j.album_file_ext')
			->join('chords_info as j','j.chords_id=t.chords_id','INNER')
			->order_by('t.chords_publish_date DESC,t.chords_id DESC')
			->get_where('chords as t',"(t.media_type_id = 2 OR t.media_type_id = 3) AND t.is_publish = '1' AND t.chords_publish_date <= NOW()",16)
			->result();
			foreach($this->data['dataChordsInter'] as $value):
				if(!empty($value->song_id)):
					$dataAlbum = $this->db->select('j.album_file_name,j.album_file_ext')
					->join('album_info as j','j.album_id=t.album_id','INNER')
					->get_where('song_album as t',array('t.song_id' => $value->song_id,'is_default' => '1'),1)
					->row();
					$value->album_file_name = $dataAlbum->album_file_name;
					$value->album_file_ext = $dataAlbum->album_file_ext;
				endif;
			endforeach;
			//Cache Set
			$this->memcache->set('dataChordsInter', $this->data['dataChordsInter'], $this->memcache_time);
		endif;
		
		//Chords Article
		if ( !$this->data['dataChordsArticleIndex'] = $this->memcache->get('dataChordsArticleIndex')):
			$this->data['dataChordsArticleIndex'] = $this->db->select('t.article_id,t.article_type,t.views,t.article_publish_date,j.article_subject,j.article_brief')
			->join('chords_article_info as j','j.article_id=t.article_id','INNER')
			->order_by('article_publish_date DESC,article_id DESC')
			->get('chords_article as t',2)
			->result();
			foreach($this->data['dataChordsArticleIndex'] as $value):
				$value->image = $this->db->order_by("article_image_order ASC,article_image_id ASC")->get_where('chords_article_image',array('article_id' => $value->article_id),1)->row();
			endforeach;			
			//Cache Set
			$this->memcache->set('dataChordsArticleIndex', $this->data['dataChordsArticleIndex'], $this->memcache_time);
		endif;				
		
		$this->data['content'] = $this->router->class."/".$this->router->method;
		$this->load->view("templates/".$this->folder_templates."templates", $this->data);
	}
	
	private function ajax_chords_pager($mode,$ajax = FALSE)
	{
		switch($mode):
			case 'Search':
				$text = $this->input->get('text');
				$letter = $this->input->get('letter');
				$per_page = 20;
				$searchCondition = "t.is_publish = '1'";
				if(!empty($letter)):
					if($letter == "other_thai"):
						$searchCondition.= " AND t.letters = '#' AND t.media_type_id = 1";
					elseif($letter == "other_eng"):
						$searchCondition.= " AND t.letters = '#' AND t.media_type_id IN (2,3)";
					else:
						$searchCondition.= " AND t.letters = '".$letter."'";
					endif;
				endif;
				if(!empty($text)):
					$searchCondition.= " AND j.song_name LIKE '%".$text."%'";
				endif;  
				$order_by = "t.chords_publish_date DESC,t.chords_id DESC";
			break;
			case 'Filter':
				$per_page = 20;
				$type = $this->uri->segment(1);
				$media_type = $this->uri->segment(2);
				$genre = $this->uri->segment(3);
				$language = $this->uri->segment(4);
				$alphabet = $this->uri->segment(5);
				$searchCondition = "t.is_publish = '1'";
				$order_by = "";
				if(!empty($type)) switch($type):	
					case 'new_released':
						$order_by .= "t.chords_publish_date DESC,t.chords_id DESC";
					break;			
					case 'hit':
						$searchCondition .= " AND DATE(t.chords_publish_date) >= DATE_SUB(CURDATE(),INTERVAL 1 MONTH)";
						$order_by = "t.views DESC";
					break;
				endswitch;
				if(!empty($media_type) && $media_type != "all"): 
					switch($media_type):	
						case 'thai':
							$searchCondition .= " AND t.media_type_id = 1";
						break;			
						case 'inter':
							$searchCondition .= " AND t.media_type_id = 2";
						break;
						case 'asian':
							$searchCondition .= " AND t.media_type_id = 3";
						break;					
					endswitch;
				endif;
				if(!empty($genre) && $genre != "all"):
					$is_exist = $this->db->from('genre')->where(array('genre_alias' => $genre))->count_all_results();
					if(empty($is_exist)) $this->page_missing();
					$searchCondition .= " AND l.genre_alias = '".$genre."'";
				endif;
				if(!empty($language) && !empty($alphabet)):
					if($alphabet == "other") $alphabet = "#";
					if($language == "e" && $media_type == "thai"):
						$searchCondition = "t.is_publish = '1' AND (t.media_type_id = 2 OR t.media_type_id = 3) AND t.letters = '".$alphabet."'";
					elseif($language == "t" && ($media_type == "inter" || $media_type == "asian")):
						$searchCondition = "t.is_publish = '1' AND t.media_type_id = 1 AND t.letters = '".$alphabet."'";
					else:
						$searchCondition .= " AND t.letters = '".urldecode($alphabet)."'";
					endif;
				endif;		
			break;
		endswitch;
		/*Pager*/		
		$config['base_url'] = current_url().'?'.query_string(array('p'));
		$config['total_rows'] = $this->db->select('COUNT(DISTINCT(t.chords_id)) as Total')
		->join('chords_genre as k','k.chords_id=t.chords_id','INNER')
		->join('genre as l','l.genre_id = k.genre_id','INNER')		
		->join('chords_info as j',"j.chords_id=t.chords_id",'INNER')
		->get_where('chords as t',$searchCondition)
		->row()->Total;		
		$config['per_page'] = $per_page;
		$config['num_links'] = 5;
		$config['first_link'] = '&laquo;';
		$config['first_tag_open'] = '<span class="first">';
		$config['first_tag_close'] = '</span>';				
		$config['last_link'] = '&raquo;';
		$config['last_tag_open'] = '<span class="last">';
		$config['last_tag_close'] = '</span>';		
		$config['next_tag_open'] = '<span class="prev">';
		$config['next_tag_close'] = '</span>';	
		$config['prev_tag_open'] = '<span class="next">';
		$config['prev_tag_close'] = '</span>';			
		$config['cur_tag_open'] = '<span class="num_tag current">';
		$config['cur_tag_close'] = '</span>';
		$config['num_tag_open'] = '<span class="num_tag">';
		$config['num_tag_close'] = '</span>';				
		$config['page_query_string'] = TRUE;
		$config['query_string_segment'] = 'p';
		$this->pagination->initialize($config);
		$this->data['pager'] = $this->pagination->create_links();
		$this->data['dataChords'] = $this->db->select('t.chords_id,t.song_id,t.views,t.chords_publish_date,j.song_name,j.artist_name,j.album_file_name,j.album_file_ext')
		->join('chords_genre as k','k.chords_id=t.chords_id','INNER')
		->join('genre as l','l.genre_id = k.genre_id','INNER')			
		->join('chords_info as j','j.chords_id=t.chords_id','INNER')
		->order_by($order_by)
		->group_by('t.chords_id')
		->get_where('chords as t',$searchCondition,$config['per_page'],intval($this->input->get('p')))
		->result();
		
		foreach($this->data['dataChords'] as $value):
			if(!empty($value->song_id)):
				$dataAlbum = $this->db->select('j.album_file_name,j.album_file_ext')
				->join('album_info as j','j.album_id=t.album_id','INNER')
				->get_where('song_album as t',array('t.song_id' => $value->song_id,'is_default' => '1'),1)
				->row();
				$value->album_file_name = @$dataAlbum->album_file_name;
				$value->album_file_ext = @$dataAlbum->album_file_ext;
			endif;
		endforeach;
		
		if($ajax):
			echo $this->load->view($this->router->class."/ajax_chords_pager", $this->data, TRUE);
			exit;
		else:
			return $this->load->view($this->router->class."/ajax_chords_pager", $this->data, TRUE);		
		endif;			
	}
	
	/*Play*/
	public function play($id = NULL,$seo_text = NULL)
	{	
		$is_exist = $this->db->from('chords')->where(array('chords_id' => $id,'is_publish' => '1'))->count_all_results();
		if(empty($is_exist)) $this->page_missing();
		
		//Rediect if no seo text
		if(empty($seo_text)):
			$dataResult = $this->db->get_where('chords_info',array('chords_id' => $id),1)->row();
			redirect($chords_url.'play/'.$id.'-'.seo_url($dataResult->song_name), 'location', 301);
		endif;	

		//UPDATE Chords (View)
		$this->db->set('views', 'views + 1', FALSE);
		$this->db->where(array('chords_id' => $id));
		$this->db->update('chords');
		
		//Keep Stat View
		$datetime = date('Y-m-d');
		$is_exist = $this->db->from('chords_click_stat')->where(array('chords_id' => $id,'update_date' => $datetime))->count_all_results();
		if(!empty($is_exist)):
			$this->db->set('chords_click_views', 'chords_click_views + 1', FALSE);
			$this->db->where(array('chords_id' => $id,'update_date' => $datetime));
			$this->db->update('chords_click_stat');
		else:
			$data = array(
				'chords_id' => $id,
				'chords_click_views' => 1,
				'update_date' => $datetime
			);
			$this->db->insert('chords_click_stat',$data);
		endif;
		
		//Load Jquery Print Area
		$this->data['js'][] = "jquery.PrintArea.js";
		$this->data['css'][] = "jquery.printArea.css";
		
		//Load Media Player
		if($this->agent->is_mobile()):
			$this->data['js'][] = "media/player.js";
		else:
			$this->data['js'][] = "media/jwplayerx.js";
		endif;			
				
		//Load Module
		$this->data['module'] = $this->module('chords');
		$this->data['module_facebook_plugins_share'] = $this->module_facebook_plugins_share();	
				
		$this->data['dataResult'] = $this->db->select('t.chords_id,t.song_id,t.views,t.chords_publish_date,j.song_name,j.artist_name,j.album_name,j.album_file_name,j.album_file_ext,j.chords_used,j.genre_tag,j.chords_tag')
		->join('chords_info as j','j.chords_id=t.chords_id','INNER')
		->order_by('t.chords_publish_date DESC,t.chords_id DESC')
		->get_where('chords as t',array('t.chords_id' => $id),1)
		->row();
		if(!empty($this->data['dataResult']->song_id)):
			$dataSongAlbum = $this->db->select('j.album_file_name,j.album_file_ext,k.create_date,l.song_file_name,l.song_file_ext,l.song_embed')
			->join('album_info as j','j.album_id=t.album_id','INNER')
			->join('song as k','k.song_id=t.song_id','INNER')
			->join('song_info as l','l.song_id=t.song_id','INNER')
			->get_where('song_album as t',array('t.song_id' =>$this->data['dataResult']->song_id,'is_default' => '1'),1)
			->row();
			$this->data['dataResult']->album_file_name = @$dataSongAlbum->album_file_name;
			$this->data['dataResult']->album_file_ext = @$dataSongAlbum->album_file_ext;
			$this->data['dataResult']->song_create_date = @$dataSongAlbum->create_date;
			$this->data['dataResult']->song_file_name = @$dataSongAlbum->song_file_name;
			$this->data['dataResult']->song_file_ext = @$dataSongAlbum->song_file_ext;
			$this->data['dataResult']->song_embed = @$dataSongAlbum->song_embed;
		endif;
		$this->data['dataResult']->chords_image = $this->db
		->order_by('chords_image_order ASC,chords_image_id ASC')
		->get_where('chords_image',array('chords_id' => $this->data['dataResult']->chords_id))
		->result();
		$this->data['dataResult']->tabs_image = $this->db
		->order_by('tabs_image_order ASC,tabs_image_id ASC')
		->get_where('chords_tabs_image',array('chords_id' => $this->data['dataResult']->chords_id))
		->result();		
		
		//Set SEO Tag
		$this->data['seo_title'] = $this->data['dataResult']->song_name.' - '.$this->data['dataResult']->artist_name.' | คอร์ดเพลง กีตาร์ You2Play.com';
		$this->data['seo_description'] = 'คอร์ดเพลง '.$this->data['dataResult']->song_name.' - '.$this->data['dataResult']->artist_name.' | '.$this->data['seo_description'];		
		$this->data['seo_keyword'] = ($this->data['dataResult']->chords_tag ? ''.$this->data['dataResult']->chords_tag:'');
					
		$this->data['fb_title'] = $this->data['seo_title'];
		if(!empty($this->data['dataResult']->album_file_name)) $this->data['fb_image'] = image_asset_url('../uploads/'.($this->data['dataResult']->song_id ? 'album':'chords').'/images/120x120/'.$this->data['dataResult']->album_file_name.'.'.$this->data['dataResult']->album_file_ext);
		
		//GA Events
		$this->data['ga_event'] = 'CI-'.$id.'-'.seo_url($this->data['dataResult']->song_name);			
		
		//Load Top Sub Menu
		$this->data['top_sub_menu'] = $this->top_sub_menu();
		
		$this->data['content'] = $this->router->class."/".$this->router->method;
		$this->load->view("templates/".$this->folder_templates."templates", $this->data);		
	}
	
	public function search()
	{	
		//Load Module
		$this->data['module'] = $this->module('chords');
		
		//Load Top Sub Menu
		$this->data['top_sub_menu'] = $this->top_sub_menu();				
		
		//Chords Search
		$this->data['dataChordsSearch'] = $this->ajax_chords_pager('Search');		
		
		$this->data['content'] = $this->router->class."/".$this->router->method;
		$this->load->view("templates/".$this->folder_templates."templates", $this->data);		
	}
	
	public function artist($sef = NULL)
	{
		if(empty($sef)) redirect("");
		$sef = urldecode($sef);
		$is_exists = $this->db->from('chords_info')->where(array('artist_sef_name' => $sef))->count_all_results();
		if(empty($is_exists)) $this->page_missing();
		
		//Load Module
		$this->data['module'] = $this->module('chords');
		
		//Load Top Sub Menu
		$this->data['top_sub_menu'] = $this->top_sub_menu();				
		
		$this->data['dataResult'] = $this->db->select('t.chords_id,t.song_id,t.views,t.chords_publish_date,j.song_name,j.artist_name,j.album_name,j.album_file_name,j.album_file_ext,j.chords_tag')
		->join('chords_info as j','j.chords_id=t.chords_id','INNER')
		->order_by('t.chords_publish_date DESC,t.chords_id DESC')
		->get_where('chords as t',array('j.artist_sef_name' => $sef))
		->result();
		
		foreach($this->data['dataResult'] as $value):
			if(!empty($value->song_id)):
				$dataAlbum = $this->db->select('j.album_file_name,j.album_file_ext')
				->join('album_info as j','j.album_id=t.album_id','INNER')
				->get_where('song_album as t',array('t.song_id' => $value->song_id,'is_default' => '1'),1)
				->row();
				$value->album_file_name = $dataAlbum->album_file_name;
				$value->album_file_ext = $dataAlbum->album_file_ext;
			endif;
		endforeach;
		
		$this->data['content'] = $this->router->class."/".$this->router->method;
		$this->load->view("templates/".$this->folder_templates."templates", $this->data);
	}
	
	public function new_released(){$this->filter('new_released');}
	public function hit(){$this->filter('hit');}
	private function filter($type = NULL)
	{
		//Load Module
		$this->data['module'] = $this->module('chords');
		
		//Load Top Sub Menu
		$this->data['top_sub_menu'] = $this->top_sub_menu();					
		
		//Chords Filter	
		$this->data['dataChordsFilter'] = $this->ajax_chords_pager('Filter');
		
		//Title
		$title = "เพลง";		
		if($type == "new_released") $title .= "ใหม่ล่าสุด";
		if($type == "hit") $title .= "ยอดนิยม";
		$this->data['title'] = $title;
		
		$this->data['content'] = $this->router->class."/filter";
		$this->load->view("templates/".$this->folder_templates."templates", $this->data);
	}
	
	/*Article*/
	public function article()
	{
		//Load Module
		$this->data['module'] = $this->module('chords');
				
		//Load Top Sub Menu
		$this->data['top_sub_menu'] = $this->top_sub_menu();
				
		//Chords Article	
		$this->memcache->delete('dataChordsArticle');
		if(!intval($this->input->get('p'))):
			if ( !$this->data['dataChordsArticle'] = $this->memcache->get('dataChordsArticle')):
				$this->data['dataChordsArticle'] = $this->ajax_article_pager('article');		
				//Cache Set
				$this->memcache->set('dataChordsArticle', $this->data['dataChordsArticle'], $this->memcache_time);
			endif;
		else:
			$this->data['dataChordsArticle'] = $this->ajax_article_pager('article');
		endif;
						
		$this->data['content'] = $this->router->class."/".$this->router->method;
		$this->load->view("templates/".$this->folder_templates."templates", $this->data);
	}
	
	private function ajax_article_pager($module = 'article', $ajax = FALSE)
	{
		$searchCondition = "t.is_publish = '1' AND t.article_publish_date <= NOW()";
		$order_by = 't.article_publish_date DESC,t.article_id DESC';
		/*Pager*/		
		$config['base_url'] = current_url().'?'.query_string(array('p'));
		$config['total_rows'] = $this->db->from('chords_article as t')
		->where($searchCondition)
		->count_all_results();	
		$config['per_page'] = 15;
		$config['num_links'] = 5;
		$config['first_link'] = '&laquo;';
		$config['first_tag_open'] = '<span class="first">';
		$config['first_tag_close'] = '</span>';				
		$config['last_link'] = '&raquo;';
		$config['last_tag_open'] = '<span class="last">';
		$config['last_tag_close'] = '</span>';		
		$config['next_tag_open'] = '<span class="prev">';
		$config['next_tag_close'] = '</span>';	
		$config['prev_tag_open'] = '<span class="next">';
		$config['prev_tag_close'] = '</span>';			
		$config['cur_tag_open'] = '<span class="num_tag current">';
		$config['cur_tag_close'] = '</span>';
		$config['num_tag_open'] = '<span class="num_tag">';
		$config['num_tag_close'] = '</span>';				
		$config['page_query_string'] = TRUE;
		$config['query_string_segment'] = 'p';
		$this->pagination->initialize($config);
		$this->data['pager'] = $this->pagination->create_links();
		$this->data['dataChordsArticle'] = $this->db->select('t.article_id,t.article_type,t.views,t.article_publish_date,j.article_subject,j.article_brief')
		->join('chords_article_info as j','j.article_id=t.article_id','INNER')
		->order_by($order_by)
		->get_where('chords_article as t',$searchCondition,$config['per_page'],intval($this->input->get('p')))
		->result();

		foreach($this->data['dataChordsArticle'] as $value):
			$value->image = $this->db->select('article_file_name,article_file_ext')
			->order_by('article_image_order ASC,article_image_id ASC')
			->get_where('chords_article_image',array('article_id' => $value->article_id),1)
			->row();
		endforeach;
		
		if($ajax):
			echo $this->load->view($this->router->class."/ajax_chords_article_pager", $this->data, TRUE);
			exit;
		else:
			return $this->load->view($this->router->class."/ajax_chords_article_pager", $this->data, TRUE);		
		endif;		
	}
	
	/*Archives*/
	public function archives($id = NULL,$seo_text = NULL)
	{	
		$is_exist = $this->db->from('chords_article')->where(array('article_id' => $id,'is_publish' => '1'))->count_all_results();
		if(empty($is_exist)) $this->page_missing();
	
		//Rediect if no seo text
		if(empty($seo_text)):
			$dataResult = $this->db->get_where('chords_article_info',array('article_id' => $id),1)->row();
			redirect($news_url.'archives/'.intval($id).'-'.seo_url($dataResult->article_subject), 'location', 301);
		endif;		

		//UPDATE Song (View)
		$this->db->set('views', 'views + 1', FALSE);
		$this->db->where(array('article_id' => $id));
		$this->db->update('chords_article');
		
		//Load Module
		$this->data['module'] = $this->module('news');
		$this->data['module_facebook_plugins_share'] = $this->module_facebook_plugins_share();
		$this->data['module_facebook_plugins_comment'] = $this->module_facebook_plugins_comment();
		
		//Load Top Sub Menu
		$this->data['top_sub_menu'] = $this->top_sub_menu();		
		
		//Load ColorBox
		$this->data['js'][] = "jquery.colorbox-min.js";	
		$this->data['css'][] = "colorbox.css";		
				
		$this->data['dataResults'] = $this->db->select('t.article_id,t.article_type,t.views,t.article_publish_date,t.create_date,j.article_subject,j.article_brief,j.article_detail,j.clip_file_name,j.clip_file_ext,j.article_tag')
		->join('chords_article_info as j','j.article_id=t.article_id','INNER')
		->order_by('t.article_publish_date','DESC')
		->get_where('chords_article as t',"t.article_id = '".$id."' AND t.is_publish = '1'",1)
		->row();
		$this->data['dataResults']->image = $this->db->order_by("article_image_order ASC,article_image_id ASC")->get_where('chords_article_image',array('article_id' => $this->data['dataResults']->article_id),1)->row();
		
		if($this->data['dataResults']->article_type == "clip"):
			//Load Media Player
			if($this->agent->is_mobile()):
				$this->data['js'][] = "media/player.js";
			else:
				$this->data['js'][] = "media/jwplayerx.js";
			endif;
		endif;
		
		//Set SEO Tag
		$this->data['seo_title'] = $this->data['dataResults']->article_subject.' | แนะนำการเล่นเพลง คอร์ด You2Play.com';
		$this->data['seo_description'] = $this->data['dataResults']->article_brief;
		$this->data['seo_keyword'] = 'แนะนำการเล่น'.($this->data['dataResults']->article_tag ? ', '.$this->data['dataResults']->article_tag:'');	
					
		$this->data['fb_title'] = $this->data['seo_title'];
		$this->data['fb_description'] = $this->data['dataResults']->article_brief;
		if(!empty($this->data['dataResults']->image)) $this->data['fb_image'] = image_asset_url('../uploads/chords/images/120x120/'.$this->data['dataResults']->image->article_file_name.'.'.$this->data['dataResults']->image->article_file_ext);
		
		//GA Events
		$this->data['ga_event'] = 'CI-'.$id.'-'.seo_url($this->data['dataResults']->article_subject);			
		
		//Load Top Sub Menu
		$this->data['top_sub_menu'] = $this->load->view($this->router->class."/top_sub_menu",$this->data, TRUE);
		
		$this->data['content'] = $this->router->class."/".$this->router->method;
		$this->load->view("templates/".$this->folder_templates."templates", $this->data);		
	}	
}


/* End of file video.php */
/* Location: ./application/controllers/video.php */